package leetcode.每日一题;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author :songyaozhang
 * @date :Created 2021/8/5 10:41
 * @description :
 */
public class 杨辉三角 {
    @Test
    public void test() {
        Solution solution = new Solution();
        List<List<Integer>> generate = solution.generate(20);
        for (List<Integer> integers : generate) {
            System.out.println(integers);
        }
    }

    class Solution {
        public List<List<Integer>> generate(int numRows) {
            List<List<Integer>> ans = new ArrayList<>();
            List<Integer> pre = new ArrayList<>();
            List<Integer> cur = null;
            for (int i = 0; i < numRows; i++) {
                cur = new ArrayList<>();
                for (int j = 0; j <= i; j++) {
                    if (j == 0 || j == i) {
                        cur.add(1);
                    } else
                        cur.add(pre.get(j - 1) + pre.get(j));
                }
                ans.add(cur);
                pre = cur;
            }
            return ans;
        }
    }
}
